package com.dongdongshop.data;

import com.dongdongshop.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Result<T> {
    private Integer code;  //返回状态码
    private String message;   //返回提示信息

    private T data;   //返回数据

    public static  Result response(ResultEnum resultEnum){
        Result result = new Result(resultEnum.getCode(),resultEnum.getMessage());
        return result;
    }

    public static Result OK(){
        Result result = new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public static Result FALL(){
        Result result = new Result(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage());
        return result;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
